import matplotlib.pyplot as plt
import numpy as np
import pandas as pd  # 是python的一个数据分析包

# Cl===============================================================

# df1 = pd.read_excel("NACA 2414/Re=60400/UIUC_Re60400.xlsx", engine='openpyxl')
# df2 = pd.read_excel("NACA 2414/Re=100800/UIUC_Re100800.xlsx", engine='openpyxl')
# df3 = pd.read_excel('NACA 2414/Re=201600/UIUC_Re201600.xlsx', engine='openpyxl')
# df4 = pd.read_excel("NACA 2414/Re=302700/UIUC_Re302700.xlsx", engine='openpyxl')

df1 = pd.read_excel("NACA 2414/Re=60400/UIUC_CS_Re60400.xlsx", engine='openpyxl')
df2 = pd.read_excel("NACA 2414/Re=100800/UIUC_CS_Re100800.xlsx", engine='openpyxl')
df3 = pd.read_excel('NACA 2414/Re=201600/UIUC_CS_Re201600.xlsx', engine='openpyxl')
df4 = pd.read_excel("NACA 2414/Re=302700/UIUC_CS_Re302700.xlsx", engine='openpyxl')

# df1 = pd.read_excel("NACA 2415/Re=60000/UIUC_Re60000.xlsx", engine='openpyxl')
# df2 = pd.read_excel("NACA 2415/Re=101300/UIUC_Re101300.xlsx", engine='openpyxl')
# df3 = pd.read_excel('NACA 2415/Re=201900/UIUC_Re201900.xlsx', engine='openpyxl')
# df4 = pd.read_excel("NACA 2415/Re=303100/UIUC_Re303100.xlsx", engine='openpyxl')

# df1 = pd.read_excel("NACA 2415/Re=60000/XFLR_Re60000.xlsx", engine='openpyxl')
# df2 = pd.read_excel("NACA 2415/Re=101300/XFLR_Re101300.xlsx", engine='openpyxl')
# df3 = pd.read_excel('NACA 2415/Re=201900/XFLR_Re201900.xlsx', engine='openpyxl')
# df4 = pd.read_excel("NACA 2415/Re=303100/XFLR_Re303100.xlsx", engine='openpyxl')

x1 = np.array(df1.iloc[:, 0])
x2 = np.array(df2.iloc[:, 0])
x3 = np.array(df3.iloc[:, 0])
x4 = np.array(df4.iloc[:, 0])
y1 = np.array(df1.iloc[:, 4])
y2 = np.array(df2.iloc[:, 4])
y3 = np.array(df3.iloc[:, 4])
y4 = np.array(df4.iloc[:, 4])
# z1 = np.array(df1.iloc[:, 4])
# z2 = np.array(df2.iloc[:, 4])
# z3 = np.array(df3.iloc[:, 4])
# z4 = np.array(df4.iloc[:, 4])

df5 = pd.read_excel("NACA 2414/Re=60400/XFLR_Re60400.xlsx", engine='openpyxl')
df6 = pd.read_excel("NACA 2414/Re=100800/XFLR_Re100800.xlsx", engine='openpyxl')
df7 = pd.read_excel('NACA 2414/Re=201600/XFLR_Re201600.xlsx', engine='openpyxl')
df8 = pd.read_excel("NACA 2414/Re=302700/XFLR_Re302700.xlsx", engine='openpyxl')

x5 = np.array(df5.iloc[:, 0])
x6 = np.array(df6.iloc[:, 0])
x7 = np.array(df7.iloc[:, 0])
x8 = np.array(df8.iloc[:, 0])
y5 = np.array(df5.iloc[:, 5])
y6 = np.array(df6.iloc[:, 5])
y7 = np.array(df7.iloc[:, 5])
y8 = np.array(df8.iloc[:, 5])
# z5 = np.array(df5.iloc[:, 4])
# z6 = np.array(df6.iloc[:, 4])
# z7 = np.array(df7.iloc[:, 4])
# z8 = np.array(df8.iloc[:, 4])

# ========================================================================================

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# =======================================================================================
figShow_Cl_Cd = plt.figure(figsize=(7, 5))
plt.xlabel('α', fontsize=15)
plt.ylabel('Cl/Cd', fontsize=15),

plt.scatter(x1, y1, c="black", s=10)
plt.plot(x1, y1, c="red", label="UIUC Re=60400", linewidth=1)
plt.plot(x5, y5, color="red", linewidth=1.0, linestyle="--", label='XFLR Re=60400')

plt.scatter(x2, y2, c="black", s=10)
plt.plot(x2, y2, c="orange", label="UIUC Re=100800", linewidth=1)
plt.plot(x6, y6, color="orange", linewidth=1.0, linestyle="--", label='XFLR Re=100800')

plt.scatter(x3, y3, c="black", s=10)
plt.plot(x3, y3, c="blue", label="UIUC Re=201600", linewidth=1)
plt.plot(x7, y7, color="blue", linewidth=1.0, linestyle="--", label='XFLR Re=201600')

plt.scatter(x4, y4, c="black", s=10)
plt.plot(x4, y4, c="green", label="UIUC Re=302700", linewidth=1)
plt.plot(x8, y8, color="green", linewidth=1.0, linestyle="--", label='XFLR Re=302700')

plt.legend(loc=2, fontsize=10, frameon=False)
plt.show()
figShow_Cl_Cd.savefig("show_Cl_Cd.svg", bbox_inches='tight')
# =======================================================================================
# plt.scatter(x1, y1, c="black", s=10)
# plt.plot(x1, y1, c="red", label="2415 XFLR Re=60000", linewidth=1)
# plt.plot(x5, y5, color="red", linewidth=1.0, linestyle="--", label='2414 XFLR Re=60400')
#
# plt.scatter(x2, y2, c="black", s=10)
# plt.plot(x2, y2, c="orange", label="2415 XFLR Re=101300", linewidth=1)
# plt.plot(x6, y6, color="orange", linewidth=1.0, linestyle="--", label='2414 XFLR Re=100800')
#
# plt.scatter(x3, y3, c="black", s=10)
# plt.plot(x3, y3, c="blue", label="2415 XFLR Re=201900", linewidth=1)
# plt.plot(x7, y7, color="blue", linewidth=1.0, linestyle="--", label='2414 XFLR Re=201600')
#
# plt.scatter(x4, y4, c="black", s=10)
# plt.plot(x4, y4, c="green", label="2415 XFLR Re=302700", linewidth=1)
# plt.plot(x8, y8, color="green", linewidth=1.0, linestyle="--", label='2414 XFLR Re=302700')
#
#
# plt.legend(loc=2, fontsize=8)
# plt.show()
# =======================================================================================
# fig1 = plt.figure(figsize=(7, 6))
# ax = Axes3D(fig1)
# ax.scatter(z1, x1, y1, s=200, c='red', marker='.',
#            alpha=0.5,
#            label='样本点')
# ax.scatter(z5, x5, y5, s=200, c='blue', marker='+', alpha=0.5,
#            label='预测点')
# ax.scatter(z2, x2, y2, s=200, c='red', marker='.',
#            alpha=0.5,
#            label='样本点')
# ax.scatter(z6, x6, y6, s=200, c='blue', marker='+', alpha=0.5,
#            label='预测点')
# ax.scatter(z3, x3, y3, s=200, c='red', marker='.',
#            alpha=0.5,
#            label='样本点')
# ax.scatter(z7, x7, y7, s=200, c='blue', marker='+', alpha=0.5,
#            label='预测点')
# ax.scatter(z4, x4, y4, s=200, c='red', marker='.',
#            alpha=0.5,
#            label='样本点')
# ax.scatter(z8, x8, y8, s=200, c='blue', marker='+', alpha=0.5,
#            label='预测点')
# # ax.set_title(title)
# ax.set_xlabel("    Re", fontsize=22)
# ax.set_ylabel("   α", fontsize=22)
# ax.set_zlabel(" Cd", fontsize=22)
# ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
# ax.zaxis.set_major_formatter(FormatStrFormatter('%.2f'))
# # ax.zaxis.set_major_locator(MultipleLocator(0.03))
# # ax.set_zticklabels(ax.get_zticklabels(),ha='right')
# ax.set_xlim(0, 310000)
# # ax.set_ylim(-16.00, 15.00)
# # plt.xticks(fontsize=20)
# # plt.yticks(fontsize=20)
# # ax.set_zticks(fontsize=20)
# # plt.savefig('fig.png', bbox_inches='tight')
# # plt.tight_layout()
# plt.legend(loc=0)  # 图例位置自
# plt.show()


# cl===================================================================================


x1 = np.array(df1.iloc[:, 0])
x2 = np.array(df2.iloc[:, 0])
x3 = np.array(df3.iloc[:, 0])
x4 = np.array(df4.iloc[:, 0])
y1 = np.array(df1.iloc[:, 1])
y2 = np.array(df2.iloc[:, 1])
y3 = np.array(df3.iloc[:, 1])
y4 = np.array(df4.iloc[:, 1])

x5 = np.array(df5.iloc[:, 0])
x6 = np.array(df6.iloc[:, 0])
x7 = np.array(df7.iloc[:, 0])
x8 = np.array(df8.iloc[:, 0])
y5 = np.array(df5.iloc[:, 1])
y6 = np.array(df6.iloc[:, 1])
y7 = np.array(df7.iloc[:, 1])
y8 = np.array(df8.iloc[:, 1])

show_Cl = plt.figure(figsize=(7, 5))
plt.xlabel('α', fontsize=15)
plt.ylabel('Cl', fontsize=15)

plt.scatter(x1, y1, c="black", s=10)
plt.plot(x1, y1, c="red", label="UIUC Re=60400", linewidth=1)
plt.plot(x5, y5, color="red", linewidth=1.0, linestyle="--", label='XFLR Re=60400')

plt.scatter(x2, y2, c="black", s=10)
plt.plot(x2, y2, c="orange", label="UIUC Re=100800", linewidth=1)
plt.plot(x6, y6, color="orange", linewidth=1.0, linestyle="--", label='XFLR Re=100800')

plt.scatter(x3, y3, c="black", s=10)
plt.plot(x3, y3, c="blue", label="UIUC Re=201600", linewidth=1)
plt.plot(x7, y7, color="blue", linewidth=1.0, linestyle="--", label='XFLR Re=201600')

plt.scatter(x4, y4, c="black", s=10)
plt.plot(x4, y4, c="green", label="UIUC Re=302700", linewidth=1)
plt.plot(x8, y8, color="green", linewidth=1.0, linestyle="--", label='XFLR Re=302700')

plt.legend(loc=2, fontsize=10, frameon=False)
plt.show()
show_Cl.savefig("show_Cl.svg", bbox_inches='tight')

# cd===============================================================================
x1 = np.array(df1.iloc[:, 0])
x2 = np.array(df2.iloc[:, 0])
x3 = np.array(df3.iloc[:, 0])
x4 = np.array(df4.iloc[:, 0])
y1 = np.array(df1.iloc[:, 2])
y2 = np.array(df2.iloc[:, 2])
y3 = np.array(df3.iloc[:, 2])
y4 = np.array(df4.iloc[:, 2])

x5 = np.array(df5.iloc[:, 0])
x6 = np.array(df6.iloc[:, 0])
x7 = np.array(df7.iloc[:, 0])
x8 = np.array(df8.iloc[:, 0])
y5 = np.array(df5.iloc[:, 2])
y6 = np.array(df6.iloc[:, 2])
y7 = np.array(df7.iloc[:, 2])
y8 = np.array(df8.iloc[:, 2])

figShow_Cd = plt.figure(figsize=(7, 5))
plt.xlabel('α', fontsize=15)
plt.ylabel('Cd', fontsize=15)

plt.scatter(x1, y1, c="black", s=10)
plt.plot(x1, y1, c="red", label="UIUC Re=60400", linewidth=1)
plt.plot(x5, y5, color="red", linewidth=1.0, linestyle="--", label='XFLR Re=60400')

plt.scatter(x2, y2, c="black", s=10)
plt.plot(x2, y2, c="orange", label="UIUC Re=100800", linewidth=1)
plt.plot(x6, y6, color="orange", linewidth=1.0, linestyle="--", label='XFLR Re=100800')

plt.scatter(x3, y3, c="black", s=10)
plt.plot(x3, y3, c="blue", label="UIUC Re=201600", linewidth=1)
plt.plot(x7, y7, color="blue", linewidth=1.0, linestyle="--", label='XFLR Re=201600')

plt.scatter(x4, y4, c="black", s=10)
plt.plot(x4, y4, c="green", label="UIUC Re=302700", linewidth=1)
plt.plot(x8, y8, color="green", linewidth=1.0, linestyle="--", label='XFLR Re=302700')

plt.legend(loc=2, fontsize=10, frameon=False)
plt.show()
figShow_Cd.savefig("show_Cd.svg", bbox_inches='tight')

# ===================================================================================
# plt.xlabel('α')
# plt.ylabel('Cd'),
#
# plt.scatter(x1, y1, c="black", s=10)
# plt.plot(x1, y1, c="red", label="2415 XFLR Re=60000", linewidth=1)
# plt.plot(x5, y5, color="red", linewidth=1.0, linestyle="--", label='2414 XFLR Re=60400')
#
# plt.scatter(x2, y2, c="black", s=10)
# plt.plot(x2, y2, c="orange", label="2415 XFLR Re=101300", linewidth=1)
# plt.plot(x6, y6, color="orange", linewidth=1.0, linestyle="--", label='2414 XFLR Re=100800')
#
# plt.scatter(x3, y3, c="black", s=10)
# plt.plot(x3, y3, c="blue", label="2415 XFLR Re=201900", linewidth=1)
# plt.plot(x7, y7, color="blue", linewidth=1.0, linestyle="--", label='2414 XFLR Re=201600')
#
# plt.scatter(x4, y4, c="black", s=10)
# plt.plot(x4, y4, c="green", label="2415 XFLR Re=303100", linewidth=1)
# plt.plot(x8, y8, color="green", linewidth=1.0, linestyle="--", label='2414 XFLR Re=302700')
#
#
# plt.legend(loc=2, fontsize=8)  #
# plt.show()

# result


df = pd.read_excel("LSTM结果.xlsx", engine='openpyxl')
R2_Cd = np.array(df.iloc[:, 1:4])
R2_Cl_Cd = np.array(df.iloc[:, 4:7])
# print(R2_Cd)
x = range(1, 10, 1)

# cd=======================================================================
result = plt.figure(figsize=(7, 5))
plt.subplots_adjust(left=0.15)
plt.plot()
plt.tick_params(labelsize=15)
plt.title('Change of $R^2$(decreases with the number of training samples)', fontsize=15)
plt.xticks(range(1, 10, 1), labels=['1/2', '1/3', '1/4', '1/5', '1/6', '1/7', '1/8', '1/9', '1/10'])
plt.xlabel('Training sample/Total sample(Wind tunnel data)', fontsize=15)
plt.ylabel('$R^2$(Cd)', fontsize=15)

plt.plot(x, R2_Cd[:, 0], label='LSTM', linestyle='--', marker='s', markerfacecolor='white')
# plt.plot(x, R2_Cd[:, 2], label='AN_MFS', linestyle='-.', marker='>', markerfacecolor='white')
plt.plot(x, R2_Cd[:, 1], label='Transfer', linestyle=':', marker='*', markerfacecolor='white')
plt.legend(loc=0, fontsize=15, frameon=False)

plt.show()
result.savefig("result_Cd.svg", bbox_inches='tight')

# Cl/Cd==========================================================================
result = plt.figure(figsize=(7, 5))
plt.plot()
plt.tick_params(labelsize=15)
plt.subplots_adjust(left=0.15)  # 图片显示不完整时使用
plt.title('Change of $R^2$(decreases with the number of training samples)', fontsize=15)
plt.xticks(range(1, 10, 1), labels=['1/2', '1/3', '1/4', '1/5', '1/6', '1/7', '1/8', '1/9', '1/10'])
plt.xlabel('Training sample/Total sample(Wind tunnel data)', fontsize=15)
plt.ylabel('$R^2$(Cl/Cd)', fontsize=15)

plt.plot(x, R2_Cl_Cd[:, 0], label='LSTM', linestyle='--', marker='s', markerfacecolor='white')
# plt.plot(x, R2_Cl_Cd[:, 2], label='AN_MFS', linestyle='-.', marker='>', markerfacecolor='white')
plt.plot(x, R2_Cl_Cd[:, 1], label='Transfer', linestyle=':', marker='*', markerfacecolor='white')
plt.legend(loc=0, fontsize=15, frameon=False)

plt.show()
result.savefig("result_Cl_Cd.svg", bbox_inches='tight')

plt.ylabel('Cd 绝对值误差', fontsize=15)
# plt.ylim(0, 0.009)

err1 = R2_Cd[:, 1] - R2_Cd[:, 0]
err2 = R2_Cd[:, 1] - R2_Cd[:, 2]
sum1 = 0
sum2 = 0

for item in err1:
    sum1 += item

for item in err2:
    sum2 += item

print("Cd预测：迁移相对未迁移提升 ", err1)
print("Cd预测：迁移相对AS-FMS提升", err2)

print("相较未迁移平均提升 ", sum1 / 9)
print("相较AS-FMS平均提升", sum2 / 9)
print("*" * 20)
# =========================================
err1 = R2_Cl_Cd[:, 1] - R2_Cl_Cd[:, 0]
err2 = R2_Cl_Cd[:, 1] - R2_Cl_Cd[:, 2]
sum1 = 0
sum2 = 0

for item in err1:
    sum1 += item

for item in err2:
    sum2 += item

print("Cd预测：迁移相对未迁移提升 ", err1)
print("Cd预测：迁移相对AS-FMS提升", err2)
print("相较未迁移平均提升 ", sum1 / 9)
print("相较AS-FMS平均提升", sum2 / 9)
# =======================================
